package day08;

import java.io.*;
import java.util.Scanner;

/**
 * 使用异常捕获完成下述操作
 * 将控制台输入的每一行字符串使用缓冲字符输出流PrintWriter
 * 按行以GBK编码写入到文件note.txt中
 * @author Bonnie
 *
 */
public class Test02 {
    public static void main(String[] args) {
        System.out.println("请输入字符串,输入-1结束: ");
        Scanner scanner = new Scanner(System.in);
        BufferedOutputStream bufferedOutputStream = null;
        PrintWriter printWriter = null;
        try {
            bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("note.txt", true));
        printWriter = new PrintWriter(bufferedOutputStream, true);
        } catch (FileNotFoundException ignored) {
        }
        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            if (s.equals("-1"))break;
            printWriter.write(s);
//            try {
//                bufferedOutputStream.write(s.getBytes());
//            } catch (IOException e) {
//                throw new RuntimeException(e);
//            }
            System.out.println(s);
        }
    }
	
}
